package com.daxue.localserver.grpc;

import com.daxue.grpc.lib.UserGrpc;
import com.daxue.grpc.lib.UserRequest;
import com.daxue.grpc.lib.UserResponse;
import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;

/**
 * @author daxue0929
 * @date 2022/9/7
 */
@GrpcService
public class GrpcUserService extends UserGrpc.UserImplBase {
    @Override
    public void sendUser(UserRequest request, StreamObserver<UserResponse> responseObserver) {
        // 1. 接收request的参数

        /**
         * 处理具体的业务逻辑
         */
        UserResponse userResponse = UserResponse.newBuilder()
            .setCode(100)
            .setMessage(
                    request.getId() + ":" + request.getName() + ":" +request.getPassword() + ":" + request.getAge())
            .build();
        responseObserver.onNext(userResponse);
        responseObserver.onCompleted();
    }
}
